<?php

namespace mpend\modules\user\models;

use Yii;
use yii\data\ActiveDataProvider;
use common\models\user\UserAddress;

/**
 * This is the model class for table "{{%user_address}}".
 *
 */
class AddressSearch extends UserAddress {

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     * @return ActiveDataProvider
     */
    public function search($params = []) {
        $query = static::find();
        $query->where(['user_id' => Yii::$app->user->id]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        Yii::$app->db->cache(function ($db) use ($dataProvider) {
            $dataProvider->prepare();
        }, 60);

        return $dataProvider;
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'name',
            'tel' => 'mobile',
            'province',
            'city',
            'county' => 'district',
            'addressDetail' => 'address_detail',
            'areaCode' => 'area_code',
            'isDefault',
            'tag'
        ];
    }

}
